package com.jdrx.sw.sewage.api.web;

import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.exception.BizException;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.EnergyReportQueryDTO;
import com.jdrx.sw.sewage.beans.dto.QualityReportQueryDTO;
import com.jdrx.sw.sewage.beans.dto.QualityReportsQueryDTO;
import com.jdrx.sw.sewage.beans.dto.ReportDTO;
import com.jdrx.sw.sewage.beans.vo.StationReportVO;
import com.jdrx.sw.sewage.beans.vo.base.PageVO;
import com.jdrx.sw.sewage.common.constant.Constant;
import com.jdrx.sw.sewage.service.StationReportServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/stationreport")
@Api(value = "数据分析")
public class StationReportApi {
    @Autowired
    private StationReportServiceImpl stationReportServiceImpl;

    @ApiOperation(value = "查询年度能耗报表list")
    @RequestMapping(value = "selectEnergyReportList", method = RequestMethod.POST)
    public ResponseVO<PageVO<StationReportVO>> selectEnergyReportList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                      @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                      @RequestBody EnergyReportQueryDTO energyReportQueryDTO) {
        return ResponseFactory2.ok(stationReportServiceImpl.selectEnergyReportList(energyReportQueryDTO));
    }

    @ApiOperation(value = "查询某一天水质报表list")
    @RequestMapping(value = "selectQualityReportList", method = RequestMethod.POST)
    public ResponseVO<Map<String, Object>> selectQualityReportList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                   @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                   @RequestBody QualityReportQueryDTO qualityReportQueryDTO) {
        return ResponseFactory2.ok(stationReportServiceImpl.selectQualityReportList(qualityReportQueryDTO));
    }

    @ApiOperation(value = "根据id修改水质或能耗报表数据 - 修改后的json前端按照原来的顺序传过来")
    @RequestMapping(value = "updateEOrQReport", method = RequestMethod.POST)
    public ResponseVO updateEOrQReport(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                       @RequestHeader(Constant.TENANT_ID) String tenantId,
                                       @RequestBody ReportDTO reportDTO) {
        return stationReportServiceImpl.updateEOrQReport(reportDTO);
    }

    @ApiOperation(value = "综合报表-导出年度能耗报表")
    @RequestMapping(value = "exportEnergyReport", method = RequestMethod.POST)
    public ResponseVO exportEnergyReport(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                         @RequestHeader(Constant.TENANT_ID) String tenantId,
                                         @RequestBody EnergyReportQueryDTO energyReportQueryDTO,
                                         HttpServletResponse response) throws BizException {
        stationReportServiceImpl.exportEnergyReport(energyReportQueryDTO, response);
        return ResponseFactory2.ok();
    }

    @ApiOperation(value = "综合报表-导出水质报表")
    @RequestMapping(value = "exportQualityReport", method = RequestMethod.POST)
    public ResponseVO exportQualityReport(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                          @RequestHeader(Constant.TENANT_ID) String tenantId,
                                          @RequestBody QualityReportsQueryDTO qualityReportsQueryDTO,
                                          HttpServletResponse response) throws Exception {
        return stationReportServiceImpl.exportQualityReport(qualityReportsQueryDTO, response);
    }
}
